package com.cskaoyan.shopping.service.impl;

import com.cskaoyan.mall.commons.exception.ValidateException;
import com.cskaoyan.shopping.constants.GlobalConstants;
import com.cskaoyan.shopping.constants.ShoppingRetCode;
import com.cskaoyan.shopping.converter.ContentConverter;
import com.cskaoyan.shopping.dal.entitys.PanelContent;
import com.cskaoyan.shopping.dal.persistence.PanelContentMapper;
import com.cskaoyan.shopping.dto.PanelContentDto;
import com.cskaoyan.shopping.service.IContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Aurhor: 徐云飞
 * @DATE: 2022/10/25 19:34
 * @Description:
 * @Version 1.0
 */
@Service
@Transactional
public class IContentServiceImpl implements IContentService {
    @Autowired
    PanelContentMapper panelContentMapper;

    @Autowired
    ContentConverter contentConverter;


    @Override
    public List<PanelContentDto> queryNavList() {

        List<PanelContentDto> panelContentDtos = null;
        try {
            PanelContent panelContent = new PanelContent();
            panelContent.setPanelId(GlobalConstants.HEADER_PANEL_ID);
            List<PanelContent> select = panelContentMapper.select(panelContent);

            panelContentDtos = contentConverter.panelContents2Dto(select);
        } catch (Exception e) {
            throw new ValidateException(ShoppingRetCode.PANEL_NOT_EXISTS.getCode(),
                    ShoppingRetCode.PANEL_NOT_EXISTS.getMessage());
        }

        return panelContentDtos;

    }
}
